<?php

require_once ('Zend/Form.php');

class Form_Result_AddQuestionNumber extends Zend_Form {
	
	private $studentID;
	private $url;
	private $update;
	
	public function __construct($options = null,$url,$studentID,$update){
		parent::__construct($options);
				
		$this->setAjaxParams($url,$studentID,$update);
		
		if(empty($this->studentID) || empty($this->url) || empty($this->update)){
			throw new Zend_Form_Exception('Set ajax params');
		}
		
		$this->setMethod('POST');
		$this->addDecorator('Fieldset',array('legend' => 'Pridelenie čísla otázky'));
		
		
		$jqueryFunction = '$.post("' . $this->url . '",{formInput: $("form input:text").val(),studentID: ' . $this->studentID . '},
						   function(data){
						   		$("' . $this->update . '").html(data);
						   },"html")';
		
		
		$formInputElement = new ZendX_JQuery_Form_Element_Spinner('question');
		$formInputElement->setLabel('Číslo otázky')
		->setAllowEmpty(false)
		->setAttrib('onKeyPress','if(event.keyCode == 13){return false}');//Ak je stlaceny ENTER tak neodosle formular
		
		
		$submit = new Zend_Form_Element_Button('submitNumber');
		$submit->setLabel('Prideliť')
		->setAttrib('onClick',$jqueryFunction);
		
		
		
		$this->addElements(array($formInputElement,$submit));
	}
	
	private function setAjaxParams($url,$studentID,$update){		
		$this->url = $url;
		$this->studentID = (int)$studentID;
		$this->update = $update;
	}
}